package juc.threadLocal;

import java.util.concurrent.TimeUnit;

public class ThreadLocalDemo {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /*
    t2t2
    t3t3
    t1t0    多次执行会出现线程不安全情况
    t0t0
    t4t4
    * */
    public static void main(String[] args) throws InterruptedException {
        ThreadLocalDemo demo = new ThreadLocalDemo();
        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                String str = Thread.currentThread().getName();
                demo.setName(str);
                System.out.println(str + demo.getName());
            }, "t" + i).start();
        }
        TimeUnit.SECONDS.sleep(1);
    }
}